package com.leetBook.Krahets.array;

import org.junit.Test;

import java.util.Arrays;

/**
 * 《图解算法与数据结构》数组第 1 题：教练使用整数数组 actions 记录一系列核心肌群训练项目编号。
 * 为增强训练趣味性，需要将所有奇数编号训练项目调整至偶数编号训练项目之前。请将调整后的训练项目编号以 数组 形式返回。
 *
 */
public class OddMove {
    public int[] trainingPlan(int[] actions) {
        int[] ints = new int[actions.length];

        int j = 0;
        for (int i = 0; i < actions.length; i++) {
            if ((actions[i] & 1) == 1){
                ints[j] = actions[i];
                j++;
            }else {
                ints[actions.length-1-i+j] = actions[i];
            }
        }

        return ints;
    }

    @Test
    public void fun1(){
        int[] actions = {1,2,3,4,5};
        System.out.println(Arrays.toString(actions));

        int[] ints = trainingPlan(actions);
        System.out.println(Arrays.toString(ints));
    }
}
